﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.Framework.Utils;

namespace CNVP.JShop.Web.Admin.CommonWindows
{
    public partial class AjaxOrderProductList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string UserID = Request.QueryString["UserID"];
            if (string.IsNullOrEmpty(UserID) || !Public.IsNumber(UserID))
            {
                UserID = "0";
            }
            String result = Request.QueryString["result"];
            if (!string.IsNullOrEmpty(result))
            {
               BLL.CNVP_Products bll_Products=  new BLL.CNVP_Products();
                string[] resultArray = result.Split(Convert.ToChar(","));
                string AddTr = "";
                for (int i = 0; i < resultArray.Length; i++)
                {
                    string[] IDSArray = resultArray[i].Split(Convert.ToChar("_"));
                    var model_Products = bll_Products.GetSingle_CNVP_ProductsById(Convert.ToInt32(IDSArray[0]));
                    if (model_Products != null)
                    {
                        string _ProductName = model_Products.ProductName;
                        string _ImgProLoad = model_Products.ImgProLoad;
                        int _ProductClassID = model_Products.ProductClassID;
                        string _ProDetailNo = model_Products.ProductNo;
                        decimal _SalePrice = model_Products.TradePrice;
                        BLL.CNVP_ProductsDetail bll_ProductsDetail = new BLL.CNVP_ProductsDetail();
                        var model_ProductsDetail = bll_ProductsDetail.GetSingle_CNVP_ProductsDetailById(int.Parse(IDSArray[1]));
                        if (model_ProductsDetail != null)
                        {
                            string StandardValueName = "";
                            string _StandardValueIDs = model_ProductsDetail.StandardValueIDs;
                            if (!string.IsNullOrEmpty(_StandardValueIDs))
                            {
                                string[] StandardIDArray = _StandardValueIDs.Split(Convert.ToChar(","));
                                StandardValueName = "(";
                                for (int k = 0; k < StandardIDArray.Length; k++)
                                {
                                    var model_StandardValue = new BLL.CNVP_StandardValue().GetSingle_CNVP_StandardValueById(int.Parse(StandardIDArray[k]));
                                    if (model_StandardValue != null)
                                    {
                                        StandardValueName += model_StandardValue.StandardValueName + "、";
                                    }
                                }

                                if (!string.IsNullOrEmpty(StandardValueName))
                                {
                                    StandardValueName = StandardValueName.Substring(0, StandardValueName.Length - 1) + ")";
                                }
                            }
                            _ProductName = _ProductName + "-" + model_ProductsDetail.ProDetailNo + "-" + StandardValueName;//组合长名称
                            _ProDetailNo = model_ProductsDetail.ProDetailNo;
                            _SalePrice = model_ProductsDetail.SalePrice;
                        }
                        AddTr += "	<tr id=\"tr" + resultArray[i] + "\">";
                        AddTr += "		<td style=\"text-align:left;\">";
                        AddTr += "		" + _ProductName + " ";
                        AddTr += "      <input type=\"hidden\" id=\"LengthName" + resultArray[i] + "\" name=\"LengthName\" value=\"" + _ProductName + "\" />";
                        AddTr += "      <input type=\"hidden\" id=\"ImgProLoad" + resultArray[i] + "\" name=\"ImgProLoad\" value=\"" + _ImgProLoad + "\" />";//图片
                        AddTr += "      <input type=\"hidden\" id=\"ProductClassID" + resultArray[i] + "\" name=\"ProductClassID\" value=\"" + _ProductClassID + "\" />";//类别
                        AddTr += "      <input type=\"hidden\" id=\"ProDetailNo" + resultArray[i] + "\" name=\"ProDetailNo\" value=\"" + _ProDetailNo + "\" />";
                        if (UserID != "0")
                        {
                            int UserLevelID = 0;
                            decimal DisCountPercent = 0;
                            var model_Users = new BLL.CNVP_Users().GetSingle_CNVP_UsersById(Convert.ToInt32(UserID));
                            if (model_Users != null)
                            {
                                UserLevelID = model_Users.UserLevelID;
                                var model_UserLevel = new BLL.CNVP_UserLevel().GetSingle_CNVP_UserLevelById(UserLevelID);
                                if (model_UserLevel != null)
                                {
                                    DisCountPercent = model_UserLevel.DisCountPercent;
                                }
                            }
                            AddTr += "      <input type=\"hidden\" id=\"SalePrice" + resultArray[i] + "\" name=\"SalePrice\" value=\"" + (_SalePrice * DisCountPercent).ToString("f2") + "\" />";
                            AddTr += "      <input type=\"hidden\" id=\"kaoPrice" + resultArray[i] + "\" name=\"kaoPrice\" value=\"" + _SalePrice + "\" />";
                        }
                        else
                        {
                            AddTr += "      <input type=\"hidden\" id=\"SalePrice" + resultArray[i] + "\" name=\"SalePrice\" value=\"" + _SalePrice + "\" />";
                            AddTr += "      <input type=\"hidden\" id=\"kaoPrice" + resultArray[i] + "\" name=\"kaoPrice\" value=\"" + _SalePrice + "\" />";
                        }
                        AddTr += "		</td>";
                        AddTr += "		<td style=\"width:20px;\">";
                        AddTr += "		<input type=\"text\" id=\"SaleNum" + resultArray[i] + "\" name=\"SaleNum\" value=\"1\" style=\"width:40px;\" onchange=\"OrderProductsOnchang('" + resultArray[i] + "');\" /></td>";
                        AddTr += "		<td style=\"width:20px;\">";
                        AddTr += "		<input id=\"BTDel" + resultArray[i] + "\" type=\"button\" value=\"删除\" onclick=\"Del('" + resultArray[i] + "')\" />";
                        AddTr += "      <input type=\"hidden\" id=\"IDS" + resultArray[i] + "\" name=\"IDS\" value=\"" + resultArray[i] + "\" />";
                        AddTr += "      <input type=\"hidden\" id=\"proID" + resultArray[i] + "\" name=\"proID\" value=\"" + IDSArray[0] + "\" />";//产品主表ID
                        AddTr += "      <input type=\"hidden\" id=\"proDetailID" + resultArray[i] + "\" name=\"proDetailID\" value=\"" + IDSArray[1] + "\" />";//详细表ID
                        AddTr += "		</td>";
                        AddTr += "	</tr>";
                    }

                }
                Response.Write(AddTr);
            }
        }
    }
}